# Django settings for hcp project.

import os
import sys

DEBUG = True
#TEMPLATE_DEBUG = DEBUG
TEMPLATE_DEBUG = False

HCP_ROOT = os.path.abspath(os.path.split(__file__)[0])

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = ''             # Or path to database file if using sqlite3.
DATABASE_USER = ''             # Not used with sqlite3.
DATABASE_PASSWORD = ''         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

HTDOCS_ROOT = os.path.join(HCP_ROOT, 'htdocs')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '6z^xy^_l+-d8gky0^j#7ak-g*o$in!hgwy9tw5b5ha12+h3$sv'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
#     'django.template.loaders.eggs.load_template_source',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.request',
    'hcp.auth.context_processor.auth',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.gzip.GZipMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'hcp.auth.middleware.AuthenticationMiddleware',
    'hcp.media.yui.YUIMiddleware',
)

ROOT_URLCONF = 'hcp.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(HCP_ROOT, 'templates'),
)

JINJA2_TEMPLATE_DIRS = (
    os.path.join(HCP_ROOT, 'templates'),
)

JINJA2_ENVIRONMENT_OPTIONS = {
#    'autoescape': True,
    'trim_blocks': True,
}

INSTALLED_APPS = (
#    'django.contrib.contenttypes',
    'django.contrib.sessions',
#    'django.contrib.sites',
    'hcp',
)

LOGIN_REDIRECT_URL = '/'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True

##############################################################################

HCP_PASSWORD_SCHEME = 'SSHA'

##############################################################################
HOME_DIRECTORY = '/home/'

USER_FIELDS_EXCLUDE = ('gecos', 'pager', 'initials', 'st', 'ou', 'postalCode', 'homePostalAddress', 'street')
GROUP_FIELDS_EXCLUDE = ()

POSIX_MIN_UID = 1000
POSIX_MIN_GID = 1000

##############################################################################
LDAP_URI = 'ldap://127.0.0.1/'
LDAP_OPTIONS = {}
LDAP_USER_DN = 'cn=Manager,dc=example,dc=com'
LDAP_USER_PASS = 'secret'
LDAP_BASE_DN = 'dc=example,dc=com'

LDAP_BASE_DN_DOMAIN = 'ou=domains,'+LDAP_BASE_DN
LDAP_BASE_DN_PERSON = 'ou=people,'+LDAP_BASE_DN
LDAP_BASE_DN_GROUP = 'ou=groups,'+LDAP_BASE_DN
LDAP_BASE_DN_HOST = 'ou=hosts,'+LDAP_BASE_DN
LDAP_BASE_DN_MAIL_ALIAS = 'ou=mail_aliases,'+LDAP_BASE_DN

try:
    from hcp.settings_local import *
except ImportError:
    sys.stderr.write('Failed to import hcp.settings_local.\n')
    sys.stderr.write('Verify that PYTHONPATH is set correctly.\n')
    sys.exit(1)

import oldap.cache
oldap.cache.initialize(LDAP_URI, LDAP_USER_DN, LDAP_USER_PASS, LDAP_OPTIONS)
